package com.frame.demo.app;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.view.inputmethod.InputMethodManager;

import com.frame.demo.R;
import com.frame.demo.widget.LoadingDialog;

/**
 * @author yuefeng
 * @version 3.3.1
 * @created at 15/12/22 下午4:59
 */
public class BaseFragmentActivity extends AppCompatActivity {
    private Dialog mLoadingDialog;

    public void showLoadingDialog() {
        showLoadingDialog(true, R.string.default_loading_message);
    }

    public void showLoadingDialog(int msgId) {
        showLoadingDialog(true, msgId);
    }

    public void showLockableLoadingDialog() {
        showLoadingDialog(false, R.string.default_loading_message);
    }

    public void showLockableLoadingDialog(int msgId) {
        showLoadingDialog(false, msgId);
    }


    public void showLoadingDialog(boolean isCancelable, int msgId) {
        if (null == mLoadingDialog) {
            mLoadingDialog = new LoadingDialog(this, isCancelable, msgId);
        }
        if (mLoadingDialog != null && !mLoadingDialog.isShowing()) {
            mLoadingDialog.show();
        }
    }

    public void dimissLoadingDialog() {
        try {
            if (null != mLoadingDialog && mLoadingDialog.isShowing()) {
                mLoadingDialog.dismiss();
            }
        } catch (Exception e) {

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (null != this && null != getCurrentFocus()) {
            InputMethodManager _Imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            _Imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); // 强制隐藏键盘
        }
    }
}
